* bites.do	JEP	03/11/15
* Generates overall bites, bites for formal and informal sectors
* Ranks the cities according to each measure
* These are bites for occupied workers


*************************** Change log ********************************** 

/*
	
*/	

clear 
version 13.1

* Project info
cap project, doinfo
if _rc==198 {
	loc master "/home/jperez/AA_Minimum_Wage"
}
else {
	local master "`r(pdir)'"
	local doname "`r(dofile)'" 
	* Project calls
	project, uses("`master'/Data/Source/ocupados_mw.dta")
	* Call programs
	project, relies_on("`master'/Code/Est/sample_choice.do")
	project, relies_on("`master'/Code/Est/build_mw_measures.do")
	project, relies_on("`master'/Code/Est/build_treatment.do")
	project, relies_on("`master'/Code/Est/export_rif.do")
	project, relies_on("`master'/Code/Est/confirmedrun.do")
}
*/


* Call necessary programs. I do not call using project to carry the programs around. I do not put these in the ado/personal folder because they are specific to the project. They are not ado files.
do "`master'/Code/Est/sample_choice.do"
do "`master'/Code/Est/build_mw_measures.do"
do "`master'/Code/Est/build_treatment.do"
do "`master'/Code/Est/export_rif.do"
do "`master'/Code/Est/confirmedrun.do"

tempfile g f iedom iidom

use "`master'/Data/Source/ocupados_mw.dta", clear

* Global - rif0
preserve
mysample rif0sample , hmin(30) hmax(50) sex(0) edadm(65) wage(salario) 
* Build mw measures
mw_measures rif0sample , stub(rif0)
* Collapse
collapse (firstnm) *bite* if time==tq(1998q4), by(ccode)
save `g'
restore

* Formal
preserve
* Choose sample
mysample rif4sample , hmin(30) hmax(50) sex(0) edadm(65) wage(salario) formal
* Build mw measures
mw_measures rif4sample , stub(rif4)
* Collapse
collapse (firstnm) *bite* if time==tq(1998q4), by(ccode)
save `f'
restore

* Informal edom
preserve
* Choose sample
mysample rif10sample , hmin(30) hmax(50) sex(0) edadm(65) wage(salario) informal
* Build mw measures
mw_measures rif10sample , stub(rif10)
* Collapse
collapse (firstnm) *bite* if time==tq(1998q4), by(ccode)
save `iedom'
restore

* Informal idom
preserve
* Choose sample
mysample rif11sample , hmin(30) hmax(50) sex(0) edadm(65) wage(salario) informal domestic
* Build mw measures
mw_measures rif11sample , stub(rif11)
* Collapse
collapse (firstnm) *bite* if time==tq(1998q4), by(ccode)
save `iidom'
restore

* Merge all measures
use `g', clear
merge 1:1 ccode using `f', nogen
merge 1:1 ccode using `iedom', nogen
merge 1:1 ccode using `iidom', nogen

drop af*

* Generate rankings

foreach x of varlist *bite* {
	sort `x'
	gen rk_`x'=_n
}

* Examine
decode ccode, gen(ccodestr)
sort ccodestr
/*
br ccode bite_rif* rank_bite_rif*
br ccode bite_e_rif* rank_bite_e_rif*
br ccode bite_fb_rif* rank_bite_fb_rif*
br ccode nom_bite_rif* rank_nom_bite_rif*
br ccode nom_bite_e_rif* rank_nom_bite_e_rif*
br ccode nom_bite_fb_rif* rank_nom_bite_fb_rif*
br ccode bite_rif* rank_bite_rif*
*/

save "`master'/Data/Source/bites.dta", replace

project, creates("`master'/Data/Source/bites.dta")








